package com.elitel.frame.base.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elitel.frame.base.service.BaseShowfieldService;
import com.elitel.frame.main.entity.BaseShowfield;
import com.elitel.frame.main.entity.ext.BaseShowfieldExt;
import com.elitel.frame.main.entity.vo.ShowFieldVo;

/**
 * @Description 配置服务显示字段Controller
 * @author guoyanfei
 * @date 2017/11/14
 */
@Controller
@RequestMapping("/system/showfield")
public class BaseShowfieldController {
	private static final Logger logger = LoggerFactory.getLogger(BaseShowfieldController.class);
	@Autowired
	private BaseShowfieldService baseShowfieldService;
	
	/**
	 * @description 通过服务ID和服务类型查询该服务的所有字段信息
	 * @param serviceId(服务ID)
	 * @param serviceType(服务类型)
	 * @param masterDetailId(主从表服务从表信息ID)
	 * @return ShowFieldVo集合
	 * @author guoyanfei
	 * @date 2017/11/14
	 *
	 */
	@RequestMapping("/getAllField")
	@ResponseBody
	@Deprecated
	public List<ShowFieldVo> getAllField(HttpServletRequest request){
		List<ShowFieldVo> showFieldVos = new ArrayList<ShowFieldVo>();
		try {
			String serviceId = request.getParameter("serviceId");
			String serviceType = request.getParameter("serviceType");
			String masterDetailId = request.getParameter("masterDetailId");
			showFieldVos = baseShowfieldService.getShowfieldByServiceId(serviceId, serviceType,masterDetailId);
			
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return showFieldVos;
	}

	@RequestMapping("/getNotExistsShowFieldInService")
	@ResponseBody
	@Deprecated
	public List<BaseShowfieldExt> getNotExistsShowFieldInService(HttpServletRequest request){
		List<BaseShowfieldExt> baseShowFieldExtList = null;
		try {
			String serviceId = request.getParameter("serviceId");
			String serviceType = request.getParameter("serviceType");
			String masterDetailId = request.getParameter("masterDetailId");
			baseShowFieldExtList = baseShowfieldService.getNotExistsShowFieldInService(serviceId, serviceType,masterDetailId);

		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return baseShowFieldExtList;
	}

	/**
	 * @description 新增该服务显示字段信息
	 * @param request
	 * @return 新增条数
	 * @author guoyanfei
	 * @date 2017/11/15
	 */
	@RequestMapping("/addShowField")
	@ResponseBody
	public Integer addShowField(@RequestBody List<BaseShowfield> baseShowfields){
		Integer result = 0;
		try {
			result = baseShowfieldService.addShowfield(baseShowfields);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return result;
	}
	
	/**
	 * 通过服务ID和服务类型查询该服务已配置的显示字段信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/getShowFieldList")
	@ResponseBody
	public List<BaseShowfieldExt> getShowFieldList(HttpServletRequest request){
		List<BaseShowfieldExt> baseShowfieldExts = new ArrayList<BaseShowfieldExt>();
		try {
			String serviceId = request.getParameter("serviceId");
			String serviceType = request.getParameter("serviceType");
			String masterDetailId = request.getParameter("masterDetailId");
			baseShowfieldExts = baseShowfieldService.getShowfieldList(serviceId, serviceType,masterDetailId);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return baseShowfieldExts;
	}
	
	/**
	 * @description 批量删除服务配置的显示字段
	 * @param guids(guid以","隔开)
	 * @return 删除条数
	 * @author guoyanfei
	 * @date 2017/11/15
	 */
	@RequestMapping("/deleteShowField")
	@ResponseBody
	public Integer deleteShowField(HttpServletRequest request){
		Integer result = 0;
		try {
			String guids = request.getParameter("guids");
			result = baseShowfieldService.deleteShowfieldByguids(guids);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return result;
	}
	
	/**
	 * @description 修改显示字段信息
	 * @param baseShowfield(显示字段实体)
	 * @return 修改条数
	 * @author guoyanfei
	 * @date 2017/11/15
	 */
	@RequestMapping("updateShowField")
	@ResponseBody
	public Integer updateShowField(@RequestBody BaseShowfield baseShowfield){
		Integer result = 0;
		try {
			result = baseShowfieldService.updateShowfield(baseShowfield);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return result;
	}

	@RequestMapping("updateShowFieldList")
	@ResponseBody
	public Integer updateShowFieldList(@RequestBody List<BaseShowfield> baseShowfieldList){
		Integer result = 0;
		try {
			result = baseShowfieldService.updateShowfieldList(baseShowfieldList);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return result;
	}



}
